//
//  RecordFactory.m
//  SimulacraDB
//
//  Created by Andre Cohen on 8/15/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "RecordFactory.h"
#import "CharRecord.h"
#import "IntRecord.h"
#import "FloatRecord.h"
#import "DateTimeRecord.h"
#import "RIDRecord.h"
#import "FixedCharRecord.h"

@implementation RecordFactory

+ (Record *)createPlainStringRecord:(NSString *)value {
	Record *r = [[[Record alloc] initWithWrapperClass:[PlainRecord class]
											dataClass:[CharRecord class]] autorelease];
	if(value)
		[[r getBlock:0] setValue:value];
	return r;
}

+ (Record *)createPlainIntRecord:(NSNumber *)value {
	Record *r = [[[Record alloc] initWithWrapperClass:[PlainRecord class]
											dataClass:[IntRecord class]] autorelease];
	if(value)
		[[r getBlock:0] setValue:value];
	return r;
}

+ (Record *)createPlainFloatRecord:(NSNumber *)value{
	Record *r = [[[Record alloc] initWithWrapperClass:[PlainRecord class]
											dataClass:[FloatRecord class]] autorelease];
	if(value)
		[[r getBlock:0] setValue:value];
	return r;
}

+ (Record *)createPlainDateTimeRecord:(NSString *)value{
	Record *r = [[[Record alloc] initWithWrapperClass:[PlainRecord class]
											dataClass:[DateTimeRecord class]] autorelease];
	if(value)
		[[r getBlock:0] setValue:value];
	return r;
}

+ (Record *)createNamespaceRecord:(NSString *)name {
	Record *r = [[[Record alloc] initWithWrapperClass:[PlainRecord class]
											dataClass:[FixedCharRecord class]] autorelease];	
	
	[(FixedCharRecord *)[r getBlock:0] setMaxLength:32];
	
	if(name)
		[[r getBlock:0] setValue:name];
	
	return r;
}

+ (Record *)createClassRecord:(NSString *)name withParent:(RID *)parent inNamespace:(RID *)ns {
	Record *r = [[[Record alloc] initWithWrapperClass:[PlainRecord class]
										dataClasses:[NSArray arrayWithObjects:[RIDRecord class],[RIDRecord class],[FixedCharRecord class],nil]] autorelease];

	[(FixedCharRecord *)[r getBlock:2] setMaxLength:32];
	
	if(name)
		[[r getBlock:2] setValue:name];
	if(parent)
		[[r getBlock:1] setValue:parent];
	if(ns)
		[[r getBlock:0] setValue:ns];
	
	return r;
}

@end
